package com.xjrsoft.module.workflow.controller;

import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.module.base.service.IXjrBaseUserService;
import com.xjrsoft.module.workflow.dto.GetPageListNwfDelegateDto;
import com.xjrsoft.module.workflow.service.IXjrNwfDelegateRelationService;
import com.xjrsoft.module.workflow.service.IXjrNwfDelegateRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Copyright 2016-2019 长沙湘北智造信息技术有限公司
 *
 * @version xbzz V2.0.28
 * @author: 湘北智造-框架开发组
 * @date:2019年12月3日
 * @url: /nwfDeleteRelation
 * @description:流程委托与模板对应关系控制器
 */
@Slf4j
@ControllerAdvice
@RestController
@RequestMapping("/workflow-Delegate")
@Api(value = "工作流委托控制器", tags = "工作流委托控制器")
public class NwfDelegateRuleController {

    @Autowired
    IXjrNwfDelegateRuleService nwfDelegateRuleService;
    @Autowired
    IXjrNwfDelegateRelationService nwfDelegateRelationService;
    @Autowired
    IXjrBaseUserService userService;

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[dto, fToUserName:被委托人]
     * @return:com.xjrsoft.common.result.Response
     * @Description:查询委托流程接口
     */
    @SneakyThrows
    @GetMapping("/query-delegate")
    @ApiOperation(value = "查询委托流程接口")
    public Response query(GetPageListNwfDelegateDto dto) {
        return Response.ok(nwfDelegateRuleService.selectDataPage(dto));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[xjrNwfDelegaterule]
     * @return:com.xjrsoft.common.result.Response
     * @Description:新增
     */
    @PostMapping()
    @ApiOperation(value = "新增")
    public Response save(@RequestBody GetPageListNwfDelegateDto dto) throws Exception {
        return Response.status(nwfDelegateRuleService.addOrUpdate(dto, SecureUtil.getUser()));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[xjrNwfDelegaterule, strSchemeInfo]
     * @return:com.xjrsoft.common.result.Response
     * @Description:更新
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "更新")
    public Response update(@RequestBody GetPageListNwfDelegateDto dto) throws Exception {
        return Response.status(nwfDelegateRuleService.addOrUpdate(dto, SecureUtil.getUser()));
    }

    /**
     * @Author:湘北智造-框架开发组
     * @Date:2020/11/9
     * @Param:[id]
     * @return:com.xjrsoft.common.result.Response
     * @Description:删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public Response delete(@PathVariable String id) {
        return Response.status(nwfDelegateRuleService.deleteDelegateRule(id));
    }
}


